// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.QueryDsl;

public sealed partial class FieldValueFactorScoreFunction
{
	/// <summary>
	/// <para>
	/// Optional factor to multiply the field value with.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("factor")]
	public double? Factor { get; set; }

	/// <summary>
	/// <para>
	/// Field to be extracted from the document.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("field")]
	public Elastic.Clients.Elasticsearch.Serverless.Field Field { get; set; }

	/// <summary>
	/// <para>
	/// Value used if the document doesn’t have that field.
	/// The modifier and factor are still applied to it as though it were read from the document.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("missing")]
	public double? Missing { get; set; }

	/// <summary>
	/// <para>
	/// Modifier to apply to the field value.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("modifier")]
	public Elastic.Clients.Elasticsearch.Serverless.QueryDsl.FieldValueFactorModifier? Modifier { get; set; }

	public static implicit operator Elastic.Clients.Elasticsearch.Serverless.QueryDsl.FunctionScore(FieldValueFactorScoreFunction fieldValueFactorScoreFunction) => Elastic.Clients.Elasticsearch.Serverless.QueryDsl.FunctionScore.FieldValueFactor(fieldValueFactorScoreFunction);
}

public sealed partial class FieldValueFactorScoreFunctionDescriptor<TDocument> : SerializableDescriptor<FieldValueFactorScoreFunctionDescriptor<TDocument>>
{
	internal FieldValueFactorScoreFunctionDescriptor(Action<FieldValueFactorScoreFunctionDescriptor<TDocument>> configure) => configure.Invoke(this);

	public FieldValueFactorScoreFunctionDescriptor() : base()
	{
	}

	private double? FactorValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Field FieldValue { get; set; }
	private double? MissingValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.FieldValueFactorModifier? ModifierValue { get; set; }

	/// <summary>
	/// <para>
	/// Optional factor to multiply the field value with.
	/// </para>
	/// </summary>
	public FieldValueFactorScoreFunctionDescriptor<TDocument> Factor(double? factor)
	{
		FactorValue = factor;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Field to be extracted from the document.
	/// </para>
	/// </summary>
	public FieldValueFactorScoreFunctionDescriptor<TDocument> Field(Elastic.Clients.Elasticsearch.Serverless.Field field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Field to be extracted from the document.
	/// </para>
	/// </summary>
	public FieldValueFactorScoreFunctionDescriptor<TDocument> Field<TValue>(Expression<Func<TDocument, TValue>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Field to be extracted from the document.
	/// </para>
	/// </summary>
	public FieldValueFactorScoreFunctionDescriptor<TDocument> Field(Expression<Func<TDocument, object>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Value used if the document doesn’t have that field.
	/// The modifier and factor are still applied to it as though it were read from the document.
	/// </para>
	/// </summary>
	public FieldValueFactorScoreFunctionDescriptor<TDocument> Missing(double? missing)
	{
		MissingValue = missing;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Modifier to apply to the field value.
	/// </para>
	/// </summary>
	public FieldValueFactorScoreFunctionDescriptor<TDocument> Modifier(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.FieldValueFactorModifier? modifier)
	{
		ModifierValue = modifier;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (FactorValue.HasValue)
		{
			writer.WritePropertyName("factor");
			writer.WriteNumberValue(FactorValue.Value);
		}

		writer.WritePropertyName("field");
		JsonSerializer.Serialize(writer, FieldValue, options);
		if (MissingValue.HasValue)
		{
			writer.WritePropertyName("missing");
			writer.WriteNumberValue(MissingValue.Value);
		}

		if (ModifierValue is not null)
		{
			writer.WritePropertyName("modifier");
			JsonSerializer.Serialize(writer, ModifierValue, options);
		}

		writer.WriteEndObject();
	}
}

public sealed partial class FieldValueFactorScoreFunctionDescriptor : SerializableDescriptor<FieldValueFactorScoreFunctionDescriptor>
{
	internal FieldValueFactorScoreFunctionDescriptor(Action<FieldValueFactorScoreFunctionDescriptor> configure) => configure.Invoke(this);

	public FieldValueFactorScoreFunctionDescriptor() : base()
	{
	}

	private double? FactorValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Field FieldValue { get; set; }
	private double? MissingValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.FieldValueFactorModifier? ModifierValue { get; set; }

	/// <summary>
	/// <para>
	/// Optional factor to multiply the field value with.
	/// </para>
	/// </summary>
	public FieldValueFactorScoreFunctionDescriptor Factor(double? factor)
	{
		FactorValue = factor;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Field to be extracted from the document.
	/// </para>
	/// </summary>
	public FieldValueFactorScoreFunctionDescriptor Field(Elastic.Clients.Elasticsearch.Serverless.Field field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Field to be extracted from the document.
	/// </para>
	/// </summary>
	public FieldValueFactorScoreFunctionDescriptor Field<TDocument, TValue>(Expression<Func<TDocument, TValue>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Field to be extracted from the document.
	/// </para>
	/// </summary>
	public FieldValueFactorScoreFunctionDescriptor Field<TDocument>(Expression<Func<TDocument, object>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Value used if the document doesn’t have that field.
	/// The modifier and factor are still applied to it as though it were read from the document.
	/// </para>
	/// </summary>
	public FieldValueFactorScoreFunctionDescriptor Missing(double? missing)
	{
		MissingValue = missing;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Modifier to apply to the field value.
	/// </para>
	/// </summary>
	public FieldValueFactorScoreFunctionDescriptor Modifier(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.FieldValueFactorModifier? modifier)
	{
		ModifierValue = modifier;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (FactorValue.HasValue)
		{
			writer.WritePropertyName("factor");
			writer.WriteNumberValue(FactorValue.Value);
		}

		writer.WritePropertyName("field");
		JsonSerializer.Serialize(writer, FieldValue, options);
		if (MissingValue.HasValue)
		{
			writer.WritePropertyName("missing");
			writer.WriteNumberValue(MissingValue.Value);
		}

		if (ModifierValue is not null)
		{
			writer.WritePropertyName("modifier");
			JsonSerializer.Serialize(writer, ModifierValue, options);
		}

		writer.WriteEndObject();
	}
}